<?php
//   +----------------------------------------------------------------------
//   | Copyright (c) 2015-2035 http://www.hdphp.cn All rights reserved.
//   | Licensed ( http://www.hdphp.cn/licenses/ )
//   | Author: Jack <sophia2152@qq.com>
//   | 官方网址: http://www.hdphp.cn
//   | 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
//   | 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
//   +----------------------------------------------------------------------

use think\Response;
use think\facade\Route;
use think\facade\Config;

/**
 * 后台管理路由配置
 */
Route::group('adminapi', function () {

    /**
     * 无需授权的接口
     */
    Route::group(function () {
        // 测试地址
        Route::get('index', 'Test/index')->option(['real_name' => '测试地址']);
        // 图形验证码
        Route::get('ajcaptcha', 'Login/ajcaptcha')->name('ajcaptcha');
        // 图形验证码
        Route::post('ajcheck', 'Login/ajcheck')->name('ajcheck');
        // 是否需要滑块验证接口
        Route::post('is_check', 'Login/getAjCaptcha')->name('getAjCaptcha');
        // 用户名密码登录
        Route::post('login', 'Login/login')->name('AdminLogin')->option(['real_name' => '用户名密码登录']);

        // 获取版权
        Route::get('copyright', 'Common/getCopyright')->option(['real_name' => '获取版权']);
    })->middleware(\app\http\middleware\AllowOriginMiddleware::class);

    /**
     * 公共相关路由
     */
    Route::group(function () {


    })->middleware([
        \app\http\middleware\AllowOriginMiddleware::class,
        \app\http\middleware\admin\AdminAuthTokenMiddleware::class,
        \app\http\middleware\admin\AdminCkeckRoleMiddleware::class,
        \app\http\middleware\admin\AdminLogMiddleware::class
    ]);


    /**
     * 用户模块 相关路由
     */
    Route::group('user', function () {


    })->middleware([
        \app\http\middleware\AllowOriginMiddleware::class,
        \app\http\middleware\admin\AdminAuthTokenMiddleware::class,
        \app\http\middleware\admin\AdminCkeckRoleMiddleware::class,
        \app\http\middleware\admin\AdminLogMiddleware::class
    ]);


    /**
     * 维护 相关路由
     */
    Route::group('system', function () {
        // 系统登录日志
        Route::get('login/log', 'v1.system.log.SystemLoginLog/index')->name('SystemLoginLog')->option(['real_name' => '系统登录日志']);
        // 系统日志
        Route::get('log', 'v1.system.log.SystemLog/index')->name('SystemLog')->option(['real_name' => '系统日志']);
        // 系统日志管理员搜索条件
        Route::get('log/search_admin', 'v1.system.log.SystemLog/search_admin')->option(['real_name' => '系统日志管理员搜索条件']);

    })->middleware([
        \app\http\middleware\AllowOriginMiddleware::class,
        \app\http\middleware\admin\AdminAuthTokenMiddleware::class,
        \app\http\middleware\admin\AdminCkeckRoleMiddleware::class,
        \app\http\middleware\admin\AdminLogMiddleware::class
    ]);


    /**
     * miss 路由
     */
    Route::miss(function () {
        if (app()->request->isOptions()) {
            $header = Config::get('cookie.header');
            $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
            return Response::create('ok')->code(200)->header($header);
        } else
            return Response::create()->code(404);
    });
})->prefix('admin.')->middleware(\app\http\middleware\InstallMiddleware::class);